#pragma once
#include "glut.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include<time.h>
#include <iostream>
#include "data.h"
using namespace std;
GLuint g_bitmap[6];//纹理对应的编号 定义纹理的映射个数 


unsigned  char *LoadBMP(const char *path, int &width, int &height)//打开纹理图片
{
	unsigned char *imagedate = NULL;
	FILE *pFile = fopen(path, "rb");
	if (pFile)
	{
		BITMAPFILEHEADER bfh;
		fread(&bfh, sizeof(BITMAPFILEHEADER), 1, pFile);
		if (bfh.bfType = 0x4d42)
		{
			BITMAPINFOHEADER bih;
			fread(&bih, sizeof(BITMAPINFOHEADER), 1, pFile);
			width = bih.biWidth;
			height = bih.biHeight;

			imagedate = new unsigned char[width*height * 3];
			fseek(pFile, bfh.bfOffBits, SEEK_SET);

			fread(imagedate, 1, width*height * 3, pFile);
			fclose(pFile);
		}
	}
	return  imagedate;
}
bool  LoadGLTextures1(char *filename, GLuint &texture)	//加载位图文件 方法1
{
	int imageWidth, imageHeight;
	unsigned char * imageDate = LoadBMP(filename, imageWidth, imageHeight);
	glGenTextures(1, &texture); //生成贴图
	glBindTexture(GL_TEXTURE_2D, texture); //贴图生效
	//纹理参数定义
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //缩小时线性滤波
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); //扩大时线性滤波
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);//超出纹理边界采用边界像素值继续填充
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, imageDate);
	return true;
}

void  LoadTextMap(void) ////纹理加载
{
	LoadGLTextures1("dibange.bmp", g_bitmap[0]);//加载第一个图
	LoadGLTextures1("computer2.bmp", g_bitmap[1]);//加载第2个图
	LoadGLTextures1("bihua.bmp", g_bitmap[2]);//加载第3个图
	LoadGLTextures1("wood2.bmp", g_bitmap[3]);//加载第3个图
	LoadGLTextures1("bizhi.bmp", g_bitmap[4]);//加载第3个图
	LoadGLTextures1("bed.bmp", g_bitmap[5]);//加载第3个图                                
}